public class Test00 {

        public static int[] distributeCandies(int candies, int n) {
            int[] dp = new int[n];
            int index = 0;
            int count = 1;
            while (true) {
                if (candies > 0 && count > candies) {
                    count =candies;
                    candies=0;

                } else {

                    candies -=count;
                    System.out.print(candies+"g");
                    System.out.print(count+"f");

                }
                dp[index] += count;
                if(candies==0) break;
                index = (index + 1) % n;
                count++;
            }
            return dp;
        }

    public static void main(String[] args) {
        int[] distributeCandies = distributeCandies(7, 4);
        System.out.println();
       for (int i = 0; i < distributeCandies.length; i++) {
           System.out.println(distributeCandies[i]);
       }
    }
}
